package com.tbit.main.controller;

import com.tbit.main.common.JsonResult;
import com.tbit.main.pojo.AccountUser;
import com.tbit.main.pojo.AccountUserWork;
import com.tbit.main.pojo.AccountUserWorkLogSta;
import com.tbit.main.service.AccountUserWorkLogService;
import com.tbit.main.service.TokenService;
import com.tbit.main.util.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 运维人员打卡日志
 *
 * @author LMY
 * @create 2021-03-23 9:39
 */
@RestController
@RequestMapping("/userWorkLog")
public class AccountUserWorkLogController {

    @Autowired
    private TokenService tokenService;
    @Autowired
    private AccountUserWorkLogService accountUserWorkLogService;

    /**
     * 分组查询
     *
     * @param token
     * @param accountId
     * @param startTime
     * @param endTime
     * @return
     */
    @RequestMapping("/groupTime")
    public JsonResult groupTime(String token, Integer accountId, String startTime, String endTime,
                                @RequestParam(value = "regionId", required = false) List<Integer> regionId) {
        AccountUser accountUserToken = tokenService.getAccount(token);
        Assert.hasLength(startTime, "System.startTime.notNull");
        Assert.hasLength(endTime, "System.endTime.notNull");
        Assert.notNull(accountId, "AccountUser.agentId.notNull");

        List<AccountUserWorkLogSta> accountUserWorkLogSta = accountUserWorkLogService.groupByTime(accountId, accountUserToken.getAccountUserType(), accountUserToken.getAccountUserId(), startTime, endTime, regionId);

        return JsonResult.succ(accountUserWorkLogSta);
    }

    /**
     * 根据时间查询
     *
     * @param token
     * @param accountId
     * @param userMainId
     * @param startTime
     * @param endTime
     * @return
     */
    @RequestMapping("/getTime")
    public JsonResult getTime(String token, Integer accountId, Integer userMainId, String startTime, String endTime, Integer mapType) {
        Assert.hasLength(startTime, "System.startTime.notNull");
        Assert.hasLength(endTime, "System.endTime.notNull");
        Assert.notNull(accountId, "AccountUser.agentId.notNull");

        List<AccountUserWork> accountUserWorkLogs = accountUserWorkLogService.getByTime(accountId, userMainId, startTime, endTime, mapType);
        return JsonResult.succ(accountUserWorkLogs);
    }
}
